"""
Xml2GUI - A powerful framework for creating GUI applications using XML files

This framework allows you to create beautiful desktop applications using simple XML files,
without writing complex Python code. It supports both PyQt5 and PyQt-Fluent-Widgets UI libraries.

Features:
- Zero programming experience required
- Intuitive XML syntax
- Automatic Python code generation
- One-click compilation to EXE
- Rich widget support
- Modern interface design
- Simplified event handling
"""

__version__ = "1.0.1"
__author__ = "huang1057"
__license__ = "GPL-3.0"

import sys
import os
from pathlib import Path

from .parser import XmlParser
from .generator import PythonGenerator
from .compiler import Compiler

__all__ = ["XmlParser", "PythonGenerator", "Compiler"]


def build_command():
    """
    模块级别的构建命令，支持 python -m xml2gui build <xml_file>
    """
    if len(sys.argv) < 3 or sys.argv[1] != "build":
        print("用法: python -m xml2gui build <xml_file> [options]")
        print("选项:")
        print("  --compile-exe, -exe    编译为可执行文件")
        print("  --output-dir, -o DIR   Python代码输出目录 (默认: dist)")
        print("  --exe-output-dir DIR   可执行文件输出目录 (默认: output)")
        print("  --icon FILE            可执行文件的图标文件")
        print("  --company NAME         公司名称")
        print("  --product NAME         产品名称")
        print("  --version VER          文件版本")
        return 1
    
    # 导入构建模块
    sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..'))
    from xml2gui_build import main
    
    # 修改sys.argv以匹配xml2gui_build的期望格式
    original_argv = sys.argv.copy()
    try:
        # 移除 'xml2gui' 和 'build' 参数
        sys.argv = [original_argv[0]] + original_argv[2:]
        return main()
    finally:
        sys.argv = original_argv


if __name__ == "__main__":
    sys.exit(build_command())